package com.meviewer.activity;

import android.Manifest;
import android.content.pm.PackageManager;

import androidx.core.app.ActivityCompat;

import com.meviewer.common.Constants;

/**
 * @author hanhaoran
 * 安卓权限校验，统一在入口校验
 */
class AppPermissions {
    private AppPermissions() {}

    private static final String [] PERMISSION_ALL = {
            Manifest.permission.INTERNET,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.ACCESS_COARSE_LOCATION
    };

    public static void verifyAllNeededPermissions(BaseActivity activity) {
        verifyPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION, PERMISSION_ALL);
    }

    private static void verifyPermission(BaseActivity activity, String permission, String[] permissions) {
        if (ActivityCompat.checkSelfPermission(activity.getApplicationContext(), permission) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(activity, permissions, Constants.ONE);
        }
    }
}
